package android.FiltrosJava;

import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;

public class ReliefFilter extends AbstractImageBasic{
    double RP = 0.2989;
    double GP = 0.5866;
    double BP = 1 - RP - GP;
    
	public BufferedImage applyFilter(BufferedImage dst) {
		BufferedImage src = copiaImagem(dst);//createCompatibleDestImage(src);
				
		int value = 128;
		int light1, light2, vlight;
		int dimX = src.getWidth();
		int dimY = src.getHeight();
		WritableRaster raster_src = src.getRaster();
    	WritableRaster raster_dst = dst.getRaster();    	
    	int[] imageData = new int[raster_src.getNumBands()]; 
		
    	for (int x = 0; x < dimX; x++){
    		
    		for (int y = 0; y < dimY; y++){
    			if ((x-3 > 0) && (y-3 > 0))
    				raster_src.getPixel(x-3,y-3,imageData);
    			else{
    				imageData[0] = 0;
    				imageData[1] = 0;
    				imageData[2] = 0;
    			}
    	    			    	
    			light1 = (int) (imageData[0] * RP + imageData[1] * GP + imageData[2] * BP);
    			
    			raster_src.getPixel(x,y,imageData);
    			light2 = (int) (imageData[0] * RP + imageData[1] * GP + imageData[2] * BP);
    			
    			vlight = delimitaCor((int) (value + light2 - light1));
    			    			
    			imageData[0] = vlight;
    			imageData[1] = vlight;
    			imageData[2] = vlight;
    		       
    			raster_dst.setPixel(x,y,imageData);
			}
		}
		
		return dst;		
    }	
}
